home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Comunications / telecom / Telecom Utilities / Quickdial 1.1 / quickdial.p < prev    next >
Encoding:
Text File  |  1993-08-27  |  3.7 KB  |  143 lines  |  [TEXT/PJMM]

  1. program quickDial;
  2.  
  3. { QuickDial takes text and dumps AT^m ATD<text>,;H to the modem. This dials the number & hangs up after 2 second. }
  4. { The program first gets text from STR id 128. This is the dialing prefix prepended to all numbers. }
  5. { Then it tries to read STR id 129. If that is blank, it tries to read the clipboard for the number. }
  6. { This way, you can have a general quickdial for all your numbers and special ones to call specific }
  7. { frequently-used (your mother, for example). }
  8. { The program will beep if there is no text in STR 129 or the clipboard. }
  9. { The program is basically meant to go under the System 7 Apple menu. }
  10. {  Unlike the few programs I looked at, I am nice & properly close the serial port when done! }
  11. { I found the source code of the Busy or Not DA by Kiron Bondale, 1988, quite useful. }
  12. { Feel free to send email to mblain@aol.com with comments/suggestions/etc... }
  13. {  Matthew Blain, 7/30/93. Public Domain. This source code can be freely distributed. }
  14. { Version 1.0.1 of 8/1/93 should close the serial port. V 1.0 didn't really. }
  15. { VErsion 1.0.2 of 8/6 does atdT (tone dial) and also sends a prelimiary AT^m }
  16. { Version 1.1 of 8/26/93 reads STR's id 128 and 129. If it is blank, it reads the clipboard. }
  17.  
  18.  
  19.     uses
  20.         Serial, Scrap;
  21.  
  22.     var
  23.         InRefNum, OutRefNum, i: integer;
  24.         waiter: longint;
  25.         Err: OSErr;
  26.         numb: str255;
  27.  
  28.     procedure init;
  29.     begin
  30. { This is the ultimate in facelessness... }
  31. { Don't even bother initializing everything }
  32. {    InitGraf(@ThePort); InitFonts; InitWindows; InitMenus; TEInit; InitDialogs(nil);}
  33. {    FlushEvents(EveryEvent, 0);}
  34.     end;
  35.  
  36.     procedure openserial;
  37.         var
  38.             config: integer;
  39.     begin
  40.         config := baud1200 + data8 + stop10 + NoParity;
  41. { Baud1200 should work with any modem! }
  42.         Err := OpenDriver('.AIn', inRefNum);
  43.         Err := OpenDriver('.AOut', OutRefNum);
  44.         Err := SerReset(InRefNum, config);
  45.         Err := SerReset(OutRefNum, config);
  46.     end;
  47.  
  48.     procedure closeserial;
  49.     begin
  50. {    Err := FSClose(OutRefNum);}
  51. {    Err := FSClose(InRefNum);}
  52.         err := closeDriver(InRefNum);
  53.         err := closeDriver(OutRefNum);
  54.         OutRefNum := 0;
  55.         InRefNum := 0;
  56.     end;
  57.  
  58.     procedure getstr (id: integer; var s: str255);
  59.         var
  60.             tHndl: StringHandle;
  61.     begin
  62.         s := '';
  63.         tHndl := GetString(id);
  64.         s := concat(' ', tHndl^^, ' ');
  65.     end;
  66.  
  67.     procedure getnumber (var numb: str255);
  68.         var
  69.             thndl: Handle;
  70.             l, offset: longInt;
  71.     begin
  72.         numb := '';
  73.         getstr(129, numb);
  74.         if (length(numb) = 2) then { 2 = blank. Why, I know not?!!! }
  75.             begin
  76.                 tHndl := NewHandle(0);
  77.                 l := GetScrap(tHndl, 'TEXT', offset);
  78.                 if (offset > 0) then { it returned something useful. }
  79.                     begin
  80.                         GetIText(tHndl, numb); { cheat conversion }
  81.                     end;
  82.             end;
  83.     end;
  84.  
  85.     procedure sendstring (s: string);
  86.         var
  87.             i: integer;
  88.             c: char;
  89.             count: LongInt;
  90.             buffer: packed array[1..10] of char;
  91.     begin
  92.         count := 1;
  93.         for i := 1 to length(s) do
  94.             begin
  95.                 buffer[1] := (s[i]);
  96.                 Err := FSWrite(OutRefNum, count, @buffer);
  97.             end;
  98.     end;
  99.  
  100.     procedure dialnumber (numb: str255);
  101.         var
  102.             prefix: str255;
  103.             modemstr: str255;
  104.     begin
  105.         prefix := '';
  106.         getstr(128, prefix);
  107.         modemstr := concat('ATD', prefix, numb, ',;H0', chr(13));
  108.         sendstring(modemstr);
  109. { Any Hayes-compatible modem should be able to handle the semicolon H0 to hang up. }
  110.     end;
  111.  
  112. { OBSOLETE procedure. 8/26/93 }
  113.     procedure sendhangup;
  114.         var
  115.             ticks: longInt;
  116.     begin
  117.         delay(65, ticks);
  118.         sendstring('+++');
  119.         delay(65, ticks);
  120.         sendstring(concat('ATH0', chr(13)));
  121.     end;
  122.  
  123.  
  124. { Main }
  125. begin
  126.     Init;
  127.     getnumber(numb);
  128.     if (length(numb) > 0) then
  129.         begin
  130.             openserial;
  131.             systemtask;
  132.             sendstring(concat('AT', chr(13)));
  133. { Wake up modem }
  134.             systemtask;
  135.             delay(60, waiter); { wait 1 seconds }
  136.             systemtask;
  137.             dialnumber(numb);
  138.             systemtask;
  139.             closeserial;
  140.         end
  141.     else
  142.         sysbeep(10); { No number found! }
  143. end.